package com.example.xiaodu.yuejian12.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xiaodu.yuejian12.Adapter.ActivityAdapter;
import com.example.xiaodu.yuejian12.Bean.ActivityBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityFragment extends Fragment {

    private RecyclerView recyclerView;
    private UserModel userModel;
    private RetrofitListener<List<ActivityBean>> listener;
    private LinearLayoutManager linearLayoutManager;
    private ActivityAdapter activityAdapter;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
      View view=inflater.inflate(R.layout.fragment_activity,container,false);
        activityAdapter=new ActivityAdapter();
        recyclerView= view.findViewById(R.id.activityRecyclerView);
        linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(activityAdapter);

        listener=new RetrofitListener<List<ActivityBean>>() {
            @Override
            public void onSuccess(List<ActivityBean> list) {
                activityAdapter.setData(list);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        userModel=new UserModel();
        userModel.getAllActivity(listener);
        return view;
    }

}
